/* eslint-disable no-mixed-spaces-and-tabs */
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import {
	isLogin
} from "../utils/tools"
Vue.use(VueRouter)

const routes = [{
		path: '/',
		name: 'Home',
		component: Home
	},
	{
		name: "List",
		path: "/List",
		component: () => import("../views/List")
	},
	{
		name: "Cart",
		path: "/Cart",
		component: () => import("../views/Cart"),
		meta: {
			needLogin: true,
			hideTabBar: true
		}
	},
	{
		name: "User",
		path: "/User",
		component: () => import("../views/User"),
		meta: {
			needLogin: true
		}
	},
	{
		name: "Detail",
		path: "/Detail",
		component: () => import("../views/Detail"),
		meta: {
			hideTabBar: true
		}
	},
	{
		name: "Reg",
		path: "/Reg",
		component: () => import("../views/Reg"),
		meta: {
			hideTabBar: true
		}
	},
	{
		name: "Login",
		path: "/Login",
		component: () => import("../views/Login"),
		meta: {
			hideTabBar: true
		}
	},
	{
		name: 'SubOrder',
		path: "/SubOrder",
		component: () => import("../views/SubOrder"),
		meta: {
			hideTabBar: true
		}
	},
	{
		name:"UserInfo",
		path:"/user_Info",
		component:()=>import("../views/UserInfo"),
		meta:{
			hideTabBar: true
		}
	  },
	  {
		name:"UserPWD",
		path:"/userpwd",
		component:()=>import("../views/UserPWD"),
		meta:{
			hideTabBar: true
		}
	  },
	{
		name: "PageNOtFount",
		path: "*",
		component: () => import("../views/PageNOtFount")
	},
]

const router = new VueRouter({
	routes
})
router.beforeEach((to, from, next) => {
	if (to.meta.needlogin) {
		if (isLogin()) {
			next()
		} else {
			next({
				name: "Login"
			})
		}
	} else {
		next()
	}
})
router.beforeEach((to, from, next) => {
	if (to.meta.needLogin) {
		if (isLogin()) {
			next();
		} else {
			next({
				name: "Login",
			});
		}
	} else {
		next();
	}
});
export default router
